package com.duleme.servlet.order;

import com.duleme.common.EncodeUtils;
import com.duleme.common.JsonUtils;
import com.duleme.entity.*;
import com.duleme.service.ShopService;
import com.duleme.service.impl.ShopServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "GetOrderServlet",urlPatterns = "/data/order/get")
public class GetOrderServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*EncodeUtils.setEncoding(request,response);
        Shop shop = (Shop) request.getSession().getAttribute("shop");
        System.out.println(shop.getShopName());
        ShopService shopService = new ShopServiceImpl();
        List<DetaileOrder> list = shopService.getDetaileOrder(shop);
        DataJson<DetaileOrder> detaileOrderData = new DataJson<>();
        detaileOrderData.setData(list);
        detaileOrderData.setCount(list.size());
        detaileOrderData.setMsg("");
        detaileOrderData.setCode("0");
        PrintWriter writer = response.getWriter();
        String detaileOrderDdataJson = JsonUtils.object2Json(detaileOrderData);
        writer.write(detaileOrderDdataJson);
        System.out.println(detaileOrderDdataJson);
        writer.close();*/
}

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        EncodeUtils.setEncoding(request,response);
        int state = Integer.valueOf(request.getParameter("state"));
        System.out.println("state:"+state);
        Shop shop = (Shop) request.getSession().getAttribute("shop");
        System.out.println(shop.getShopName());
        ShopService shopService = new ShopServiceImpl();
        List<DetaileOrder> list = shopService.getDetaileOrderBystate(shop, state);
        DataJson<DetaileOrder> detaileOrderData = new DataJson<>();
        detaileOrderData.setData(list);
        detaileOrderData.setCount(list.size());
        detaileOrderData.setMsg("");
        detaileOrderData.setCode("0");
        PrintWriter writer = response.getWriter();
        String detaileOrderDdataJson = JsonUtils.object2Json(detaileOrderData);
        writer.write(detaileOrderDdataJson);
        System.out.println("json:"+detaileOrderDdataJson);
        writer.close();
    }
}
